package com.spic.system.api;

import com.spic.common.core.constant.ServiceNameConstants;
import com.spic.common.core.domain.R;
import com.spic.system.api.domain.FileDomain;
import com.spic.system.api.domain.SysFile;
import com.spic.system.api.dto.DownloadFileDTO;
import com.spic.system.api.dto.SysFileRecord;
import com.spic.system.api.factory.RemoteFileFallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

/**
 * 文件服务
 *
 * @author ruoyi
 */
@FeignClient(contextId = "remoteFileService", value = ServiceNameConstants.FILE_SERVICE, fallbackFactory = RemoteFileFallbackFactory.class)
public interface RemoteFileService {
    /**
     * 上传文件
     *
     * @param file 文件信息
     * @return 结果
     */
    @PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    R<SysFile> upload(@RequestPart(value = "file") MultipartFile file);

    /**
     * 从网络下载文件并上传到minio桶中
     *
     * @param file 文件信息
     * @return 结果
     */
    @PostMapping("/upload_filePath")
    R<String> uploadOfFilePath(@RequestBody FileDomain file);

    /**
     * 获取文件URL
     *
     * @param ids
     * @return
     */
    @PostMapping("/get_file_url")
    R<Map<String, SysFileRecord>> getFileRecord(@RequestBody List<String> ids);

    /**
     * 打包到本地
     */
    @PostMapping("/downloadfilelistCache")
    R<Map<String, SysFileRecord>> downloadfilelistCache(DownloadFileDTO downloadFileDTO);

    @GetMapping("/getSysFileRecordByOriginalUrl")
    R<String> getSysFileRecordByOriginalUrl(@RequestParam("originalUrl") String originalUrl);

    @GetMapping("/getwatermarkImageUrl")
    R<String> getwatermarkImageUrl(@RequestParam("url") String url, @RequestParam("text") String text);

    @GetMapping("getFileByUrl")
    R<SysFileRecord> getFileByUrl(@RequestParam("url") String url);

}
